package me.huangxiang.springlearnning.dynamic_proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

public class DynamicProxyMain {
    public static void main(String[] args) {
        // 通过这个实例理解通过JDK方式实现动态代理的原理

        UserService userService = new UserServiceImpl();
        InvocationHandler invocationHandler = new MyInvocationHandler(userService);

        UserService userServiceProxy = (UserService) Proxy.newProxyInstance(userService.getClass().getClassLoader(),
                userService.getClass().getInterfaces(), invocationHandler);

        System.out.println(userServiceProxy.getAge(1));
        System.out.println(userServiceProxy.getName(1));
    }
}
